package com.example.zwgt.yrfk.ui.access.presenter;


import android.annotation.SuppressLint;
import android.util.Log;

import com.blankj.utilcode.util.ToastUtils;
import com.example.zwgt.yrfk.base.mvpbase.baseImpl.BasePresenterImpl;
import com.example.zwgt.yrfk.retroft.Api;
import com.example.zwgt.yrfk.retroft.ExceptionHelper;
import com.example.zwgt.yrfk.ui.access.contact.AccessListContact;
import com.example.zwgt.yrfk.ui.main.contact.LoginContact;

import java.util.HashMap;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/*
 * 项目名:    BaseFrame
 * 包名       com.zhon.frame.mvp.login.presenter
 * 文件名:    AccessListPresenter
 * 创建者:
 * 创建时间:  2018/7/10 on 16:24
 * 描述:     TODO
 */
public class AccessListPresenter extends BasePresenterImpl<AccessListContact.view>
        implements AccessListContact.presenter {

    public AccessListPresenter(AccessListContact.view view) {
        super(view);
    }

    @SuppressLint("CheckResult")
    @Override
    public void getAccessList() {
        Api.getInstance().getGuestList("app-customer", new HashMap<>())
                .subscribeOn(Schedulers.io())
                .doOnSubscribe(disposable -> {
                    addDisposable(disposable);
                    view.showLoadingDialog();
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(storiesBeen -> {
                    view.dismissLoadingDialog();
                    //处理服务器返回的数据
                    if (storiesBeen.getStatus().equals("1")) {
                           view.getLoadData(storiesBeen.getContent());
                        //处理服务器返回的错误信息
                    } else {
                        ToastUtils.showShort(storiesBeen.getMsg());
                    }
                    //处理网络异常
                }, throwable -> {
                    view.dismissLoadingDialog();
                    ExceptionHelper.handleException(throwable);
                });


    }
}
